﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class DateaBestHelp
    {

        public static void jian()
        {
            string connectionString = "server =.;database= huan;uid=sa;pwd=123456";


            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            var sqlcommandstring = "select*from student";
            SqlCommand sqlCommand = new SqlCommand(sqlcommandstring, sqlConnection);
            var sdr = sqlCommand.ExecuteReader();
            while (sdr.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", sdr["stuid"], sdr["stuname"], sdr["stuage"]);

            }
            sqlConnection.Close();

        } 

        public void jin()
        {
            string connectionString = "server =.;database= huan;uid=sa;pwd=123456";


            SqlConnection sqlConnection = new SqlConnection(connectionString);
            sqlConnection.Open();
            var sqlcommandstring = "select*from student";
            SqlDataAdapter sqldataAdapter = new SqlDataAdapter(sqlcommandstring, connectionString);

            DataTable DDD = new DataTable();


            sqldataAdapter.Fill(DDD);
            Console.WriteLine("{0}\t{1}\t{2}\t{3}", "stuid", "stuname", "stuage");


            Console.WriteLine();


            Console.WriteLine();


            for (int i = 0; i < DDD.Rows.Count; i++)
            {
                Console.WriteLine("{0}\t{1}\t{2}\t{3}", DDD.Rows[i]["id"], DDD.Rows[i]["Username"], DDD.Rows[i]["Password"], DDD.Rows[i]["Createdtime"]);
            }
        }
    }
}
